import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import static junit.framework.Assert.assertTrue;

public class AddingContextToActions {

    static WebDriver driver;
    static WebDriverWait wait;
    DataChangeCheck dataChange = new DataChangeCheck();
    static int addingContextCount, contextCount;

    @BeforeClass
public static void  successfulLoginTest (){
        driver = FireFoxDriver.createFireFoxDriver();
        wait = new WebDriverWait(driver,10);
        Login loginPage = new Login(driver);
        loginPage.typeUserName();
        loginPage.typePassword();
        loginPage.clickSignIn(wait, PageVariableValues.homePageTitle);
    }

@Test
public void addContextToActionFromContextPage () {

    Navigation goToOrganizeMenu = new Navigation(driver);
    goToOrganizeMenu.topNavigationSub(PageVariableValues.organizeLink, PageVariableValues.contextsLink, PageVariableValues.contextsPageTitle);

    addingContextCount = dataChange.getContextCount(driver);

    WebElement findContextForm = driver.findElement(By.id("context_new_container"));
    WebElement enterContextName = findContextForm.findElement(By.id("context_name"));

    DateFormat dateFormat = new SimpleDateFormat("dd MM yyyy HHmm");
    Calendar cal = Calendar.getInstance();
    String currentDate = dateFormat.format(cal.getTime());


    //String currentDate = "current date";
    String newContextName = "context3Test " + currentDate;
    //context3test 22042013 1556
    enterContextName.sendKeys(newContextName);

    WebElement addContextSubmit = findContextForm.findElement(By.id("context_new_submit"));
    addContextSubmit.click();

    int expectedContextCount = addingContextCount + 1;
    new WebDriverWait(driver,5).until(ExpectedConditions.textToBePresentInElement(By.id("badge_count"),"" + expectedContextCount));
    contextCount = dataChange.getContextCount(driver);

    assertTrue("the context count should increase when context has been added ", contextCount > addingContextCount);

   // mainMenu.topNavigationSub(driver, PageVariableValues.organizeLink, PageVariableValues.contextsLink);

    // navigate to organize menu
    // click on context option

}

    @AfterClass
    public static void cleanUpTest(){
        driver.close();
        driver.quit();
    }
}
